.PHONY: help install test run-flask run-celery run-dev test-api clean format lint

help:  ## 显示帮助信息
	@echo "可用命令："
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "  %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

install:  ## 安装依赖
	uv sync

test:  ## 运行测试
	uv run python test_setup.py

run-flask:  ## 启动 Flask 应用
	uv run python main.py

run-celery:  ## 启动 Celery Worker
	uv run celery -A app.tasks.export_tasks worker --loglevel=info

run-dev:  ## 启动开发环境（需要多个终端）
	@echo "请在不同的终端中分别运行："
	@echo "  make run-flask"
	@echo "  make run-celery"

test-api:  ## 测试 API（需要先启动服务）
	uv run python test_api.py

clean:  ## 清理临时文件
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete
	find . -type d -name "*.egg-info" -exec rm -rf {} +

format:  ## 格式化代码
	uv run black .

lint:  ## 代码检查
	uv run flake8 .

# 数据库相关命令
db-init:  ## 初始化数据库迁移
	uv run flask db init

db-migrate:  ## 创建数据库迁移
	uv run flask db migrate -m "Migration"

db-upgrade:  ## 应用数据库迁移
	uv run flask db upgrade

# 开发工具
dev-deps:  ## 安装开发依赖
	uv sync --extra dev

shell:  ## 进入 Python shell
	uv run python -i -c "from app import create_app; app = create_app()"
